package io.gitee.xyuesheng.day08;

import org.junit.Test;

import java.io.*;

public class TestFile {
    @Test
    public void testFile() throws IOException {
        File file = new File("D:\\test.txt");

        //受检异常，必须显式的try...catch
        try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file))) {
            reader.read();
        } catch (FileNotFoundException e) {
            //往文件里面写
            e.printStackTrace();
            //往控制台打异常消息是不规范的
        } catch (IOException e) {
            throw e;
//            e.printStackTrace();
        } finally {
            System.out.println(" ");
        }

    }

    @Test
    public void testRuntimeException() {
        try {
//            File f=null;
//            f.exists();

//            return;
            System.exit(0);

        } catch (Exception e) {
            System.out.println("空指针异常。。");
            e.printStackTrace();
        } finally {
            System.out.println("finally...");
        }
    }

}
